package cn.kuaipan.android.sdk.activity;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import cn.kuaipan.android.sdk.KPManager;
import cn.kuaipan.android.sdk.R;
import cn.kuaipan.android.sdk.entity.MyApplication;
import cn.kuaipan.android.sdk.ui.KPAuthView;
import cn.kuaipan.client.model.KuaipanFile;
import cn.kuaipan.client.model.KuaipanUser;

import com.umeng.android.utils.Constants;

public class MainActivity extends Activity {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        KPManager.init("xccWrYofcxLtGHDZ", "Z8vFI1lLzLLRk7lT");
		Intent intent = new Intent(this,
				KPAuthView.class);
		startActivity(intent);
        setContentView(R.layout.main);
        initFrameView();
    }
    
	private void initFrameView() {
		// TODO Auto-generated method stub
		findViewById(R.id.user_info).setOnClickListener(new MyOnClickListener());
		findViewById(R.id.folder_info).setOnClickListener(new MyOnClickListener());
	}

	public static Handler handler = new Handler(){
		public void handleMessage(android.os.Message msg) {
			switch (msg.arg1) {
			case Constants.SUCCESS:
				dealMessage(msg);
				break;
			case Constants.FAIL:
				
				break;
			default:
				break;
			}
		};
	};
	
	/**
	 * deal with message
	 * @param msg
	 */
	protected static void dealMessage(Message msg) {
		
		switch (msg.arg2) {
		case Constants.USER_COPY_FOLDER:
			
			break;

		case Constants.USER_CREATE_FOLDER:
			
			break;
		case Constants.USER_DELETE_FOLDER:
			
			break;
		case Constants.USER_DOWNLOAD_FILE:
			
			break;
		case Constants.USER_FILE_THUMBNAIL:
			
			break;
		case Constants.USER_FOLDER:
			KuaipanFile file = (KuaipanFile) msg.obj;
			for(KuaipanFile f:file.files){
				System.out.println(f.name);
			}
			break;
		case Constants.USER_INFO:
			KuaipanUser user = (KuaipanUser) msg.obj;
			System.out.println(user.user_name);
			break;
		case Constants.USER_LOGIN:
			
			break;
		case Constants.USER_MOVE_FOLDER:
			
			break;
		case Constants.USER_SHARE_LINK:
			
			break;
		case Constants.USER_UPLOAD_FILE:
			
			break;
	
		}
	}
	
	private class MyOnClickListener implements OnClickListener{

		@Override
		public void onClick(View view) {
			switch (view.getId()) {
			case R.id.user_info:
				MyApplication.getManager().getUserInfo();
				break;

			case R.id.folder_info:
				MyApplication.getManager().getFolderInfo("/我的应用");
				break;
			}
			
		}
		
	}
}
